home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Commands / Add Remove NS Resize Fix.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  3.0 KB  |  94 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved
  2.  
  3. //---------------     API FUNCTIONS    ---------------
  4.  
  5. function commandButtons() {
  6.   var addCmd    =  "addNSResizeFix(); window.close();";
  7.   var removeCmd =  "removeNSLayerFix(); window.close();";
  8.   var retArr;
  9.  
  10.   // Include only buttons that make sense for the current selection.
  11.   if (!dw.getDocumentDOM()) {
  12.     retArr = new Array( 
  13.                       BTN_Cancel,   "window.close()"
  14.                     );
  15.   } else if (hasNSLayerFix() ){
  16.     retArr = new Array( 
  17.                       BTN_Remove,   removeCmd,
  18.                       BTN_Cancel,   "window.close()"
  19.                     );
  20.   } else {
  21.     retArr = new Array( 
  22.                       BTN_Add,       addCmd,
  23.                       BTN_Cancel,   "window.close()"
  24.                     );
  25.   }
  26.   return retArr;
  27. }
  28.  
  29. function canAcceptCommand() {
  30.   return (dw.getFocus() == 'document');
  31. }
  32.  
  33.  
  34. //---------------    LOCAL FUNCTIONS   ---------------
  35.  
  36.  
  37. function initializeUI() {
  38.   if (dw.getDocumentDOM() == null) return;
  39.   if (hasNSLayerFix()) {
  40.     document.mainForm.addMsg.visibility = "hidden";
  41.     document.mainForm.removeMsg.visibility = "visible";
  42.   } else {
  43.     document.mainForm.removeMsg.visibility = "hidden";
  44.     document.mainForm.addMsg.visibility = "visible";
  45.   }
  46. }
  47.  
  48. function nsScriptToInsert (bAddScript) {
  49.   var rtnStr = '';
  50.   rtnStr = 'function MM_reloadPage(init) %7B  //reloads the window if Nav4 resized%0D  if (init==true) with (navigator) %7Bif ((appName=="Netscape")&&(parseInt(appVersion)==4)) %7B%0D    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; %7D%7D%0D  else if (innerWidth!=document.MM_pgW %7C%7C innerHeight!=document.MM_pgH) location.reload();%0D%7D%0DMM_reloadPage(true);%0D';
  51.   if (bAddScript) {
  52.     rtnStr = '%3Cscript language=%22JavaScript%22%3E%0D%3C!--%0D' + rtnStr + '// --%3E%0D%3C/script%3E%0D';
  53.   }
  54.   return unescape(rtnStr);
  55. }
  56.  
  57.  
  58. function hasNSLayerFix() {
  59.   return hasFunctionCall('MM_reloadPage');
  60. }
  61.  
  62.  
  63. function addNSResizeFix() {
  64.   var retVal = false;
  65.   var dom = dw.getDocumentDOM();
  66.   var head = dom.getElementsByTagName('head');
  67.   if (head && head.length > 0 && !hasNSLayerFix()) {
  68.     // Add the entire fix and script tag.
  69.     head[0].innerHTML += '\n' + nsScriptToInsert(true);
  70.     retVal = true;
  71.   } else { retVal = false;} // No head, fail to insert.
  72.   return retVal;
  73. }
  74.  
  75.  
  76. function removeNSLayerFix() {
  77.   var curDOM = dw.getDocumentDOM();
  78.   var inNode;
  79.   // Look for exactly what we add, if the entire tag, comment and script are
  80.   //  intact then remove the entire block.
  81.   var curHTML = curDOM.documentElement.outerHTML;
  82.   var nsFixStr = nsScriptToInsert(true);
  83.   var nsFixLoc = curHTML.indexOf(nsFixStr);
  84.   if (nsFixLoc != -1) {
  85.     curHTML = curHTML.slice(0,nsFixLoc) + curHTML.slice(nsFixLoc + nsFixStr.length);
  86.     curDOM.documentElement.outerHTML = curHTML;
  87.   }
  88.   // Otherwise, remove the function and calls.
  89.   // Remove any calls to the function.
  90.   while (deleteFunction('MM_reloadPage')) {};
  91.   // Note: deleteFunctionCall removes the script if empty.
  92.   while (deleteFunctionCall('MM_reloadPage')) {};
  93. }
  94.